<?php

/**
 * Created by PhpStorm
 * User Niu Yong Qiang
 * Date 2021/9/17 19:20
 */

namespace App\Services\Web;

use App\Http\Format\FormatBase;
use App\Models\SysMessageModel;
use App\Models\SysPermissionsModel;
use App\Models\SysRoleModel;
use App\Models\SysRolePermissionsModel;
use App\Models\SysUserModel;
use App\Models\TableItemModel;
use App\Models\TableModel;
use App\Models\UserTokenModel;
use App\Models\SysUserRoleModel;
use App\Services\CommonService;
use Exception;

class TableService extends CommonService
{
    public function handleItemParams($params)
    {
        $id = 0;
        $title = '';
        $data = [];
        //处理参数
        if (!empty($params['id'])){
            $id = $params['id'];
        }

        if (!empty($params['style'])){
            $data['style'] = $params['style'];
        }

        if (!empty($params['pid'])){
            $data['pid'] = $params['pid'];
        }

        if (!empty($params['choose_number'])){
            $data['choose_number'] = $params['choose_number'];
        }

        if (!empty($params['title'])){
            $title = $data['title'] = $params['title'];

        }

        if (!empty($params['attr'])){
            $data['attr'] = $params['attr'];
        }

        if (!empty($params['check'])){
            $data['check'] = $params['check'];
        }

        if (!empty($params['max'])){
            $data['max'] = $params['max'];
        }

        if (!empty($params['min'])){
            $data['min'] = $params['min'];
        }

        if (!empty($params['display'])){
            $data['display'] = $params['display'];
        }

        if (!empty($params['allow_symbol'])){
            $data['allow_symbol'] = $params['allow_symbol'];
        }

        if (!empty($params['allow_symbol_msg'])){
            $data['allow_symbol_msg'] = $params['allow_symbol_msg'];
        }

        if (!empty($params['fill'])){
            $data['fill'] = $params['fill'];
        }

        if (!empty($params['show'])){
            $data['show'] = $params['show'];
        }

        if (!empty($params['case'])){
            $data['case'] = $params['case'];
        }

        if (!empty($params['sort'])){
            $data['sort'] = $params['sort'];
        }

        if (!empty($params['head_field'])){
            $data['head_field'] = $params['head_field'];
        }

        if (!empty($params['show_msg'])){
            $data['show_msg'] = $params['show_msg'];
        }

        if (!empty($params['msg'])){
            $data['msg'] = $params['msg'];
        }

        if (!empty($params['show_count'])){
            $data['show_count'] = $params['show_count'];
        }

        if (!empty($params['table_style'])){
            $data['table_style'] = $params['table_style'];
        }

        //选项内容
        if (!empty($params['option_content'])){
            $data['option_content'] = json_encode($params['option_content']);
        }

        if (!empty($params['multiple_choose'])){
            $data['multiple_choose'] = $params['multiple_choose'];
        }

        if (!empty($params['choose_num'])){
            $data['choose_num'] = $params['choose_num'];
        }

        if (!empty($params['search'])){
            $data['search'] = $params['search'];
        }

        if (!empty($params['tips'])){
            $data['tips'] = $params['tips'];
        }

        if (!empty($params['date_area_style'])){
            $data['date_area_style'] = $params['date_area_style'];
        }

        if (!empty($params['date_equal'])){
            $data['date_equal'] = $params['date_equal'];
        }

        if (!empty($params['msg_tips'])){
            $data['msg_tips'] = $params['msg_tips'];
        }

        if (!empty($params['accessory_style'])){
            $data['accessory_style'] = json_encode($params['accessory_style']);
        }

        if (!empty($params['accessory_image_size'])){
            $data['accessory_image_size'] = $params['accessory_image_size'];
        }

        if (!empty($params['accessory_image_num'])){
            $data['accessory_image_num'] = $params['accessory_image_num'];
        }

        if (!empty($params['accessory_video_size'])){
            $data['accessory_video_size'] = $params['accessory_video_size'];
        }

        if (!empty($params['accessory_video_num'])){
            $data['accessory_video_num'] = $params['accessory_video_num'];
        }

        if (!empty($params['cellphone_uplode'])){
            $data['cellphone_uplode'] = $params['cellphone_uplode'];
        }

        if (!empty($params['group_uplode'])){
            $data['group_uplode'] = $params['group_uplode'];
        }

        return [$id, $title, $data];

    }

    public function databaseItem($id, $data)
    {
        if (empty($id)){
            //添加
            $id = TableItemModel::insertSingle($data);

        }else{
            //修改
            TableItemModel::updateSingle(['id'=> $id], $data);

        }

        return $id;
    }

    public function database($id, $data)
    {
        if (empty($id)){
            //添加
            TableModel::insertSingle($data);

        }else{
            //修改
            TableModel::updateSingle(['id'=> $id], $data);

        }


    }

    public function databaseTable($id, $data)
    {
        if (empty($id)){
            //添加
            TableModel::insertSingle($data);

        }else{
            //修改
            TableModel::updateSingle(['id'=> $id], $data);

        }


    }
}
